//
//  VehicleAdditionCell.m
//  StarOrangeStaff
//
//  Created by lshenrong on 2020/6/30.
//  Copyright © 2020 lshenrong. All rights reserved.
//

#import "VehicleAdditionCell.h"

@interface VehicleAdditionCell ()

@property (nonatomic,strong) UILabel *titleLbl;
@property (nonatomic,strong) CedarButton *leftBtn;
@property (nonatomic,strong) UILabel *leftLbl;

@property (nonatomic,strong) CedarButton *rightBtn;
@property (nonatomic,strong) UILabel *rightLbl;


@end

@implementation VehicleAdditionCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self!=nil){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLbl];
        [self.contentView addSubview:self.leftBtn];
        [self.contentView addSubview:self.rightBtn];
        [self.contentView addSubview:self.leftLbl];
        [self.contentView addSubview:self.rightLbl];

        
        [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView).mas_offset(kMarginOffsetX);
            make.centerY.mas_equalTo(self.contentView.mas_centerY);
        }];
        
        [self.rightLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).mas_offset(-kMarginOffsetX);
            make.centerY.mas_equalTo(self.contentView.mas_centerY);
        }];
        
        [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.rightLbl.mas_left).mas_offset(-5);
            make.centerY.mas_equalTo(self.contentView.mas_centerY);
        }];
        
        
        [self.leftLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.rightBtn.mas_left).mas_offset(-kMarginOffsetX * 2);
            make.centerY.mas_equalTo(self.contentView.mas_centerY);
        }];
        [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.leftLbl.mas_left).mas_offset(-5);
            make.centerY.mas_equalTo(self.contentView.mas_centerY);
        }];
    }
    return self;
}

- (CedarButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [CedarButton buttonWithType:UIButtonTypeCustom];
        [_leftBtn setImage:[UIImage imageNamed:@"license_unselect"] forState:UIControlStateNormal];
        [_leftBtn setImage:[UIImage imageNamed:@"license_select"] forState:UIControlStateSelected];
        [_leftBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _leftBtn;
}

- (CedarButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [CedarButton buttonWithType:UIButtonTypeCustom];
        [_rightBtn setImage:[UIImage imageNamed:@"license_unselect"] forState:UIControlStateNormal];
        [_rightBtn setImage:[UIImage imageNamed:@"license_select"] forState:UIControlStateSelected];
        [_rightBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightBtn;
}


- (void)btnClicked:(UIButton *)sender{
    for (UIButton *button in self.contentView.subviews) {
        if ([button isMemberOfClass:[CedarButton class]]) {
            button.selected = NO;
        }
    }
    sender.selected = YES;
}


MACRO_UILabel_LazyloadWithPFCGFont(titleLbl, @"双牌照", kBlackColor, 15)

MACRO_UILabel_LazyloadWithPFCGFont(leftLbl, @"是", kBlackColor, 15)
MACRO_UILabel_LazyloadWithPFCGFont(rightLbl, @"否", kBlackColor, 15)


@end
